# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from aip import AipSpeech
import pygame
import time


""" 你的 APPID AK SK """
APP_ID = '9729136'
API_KEY = '8gBb5mb9aEu1Pf3sbuzw1qvU'
SECRET_KEY = 'H7gVkowAKSGiX6YmZ43665zLf7XBCh0o'
aipSpeech = AipSpeech(APP_ID, API_KEY, SECRET_KEY)

while True:
	str = input("输入文字:");
	result  = aipSpeech.synthesis(str, 'zh', 1, {
	    'vol': 5,
	})
	# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
	if not isinstance(result, dict):
	    with open('auido.mp3', 'wb') as f:
	        f.write(result)

	pygame.mixer.init()
	pygame.mixer.music.load(r'auido.mp3')
	pygame.mixer.music.play()
	print("run...")
	time.sleep(1)
	print('stop')